﻿using Logistics.Storage;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using AutoMapper;

namespace Logistics.Web.Controllers
{
    public class EntrepotController : Controller
    {
        private readonly WarehousingAppService _warehousingAppService;

        public EntrepotController(WarehousingAppService warehousingAppService)
        {
            _warehousingAppService = warehousingAppService;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task DeleteAsyncc(int id)
        {
            var i = _warehousingAppService.DeleteAsync(id);
            return i;
        }
        /// <summary>
        /// 查看视图
        /// </summary>
        /// <returns></returns>
        public ActionResult GetWarehousingIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 反填视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PutWarehousingIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        public IActionResult Updates(WarehousingDto Warehousing)
        {
            var procur = _warehousingAppService.UpdateAsync(Warehousing);
            return Ok(procur);
        }

        /// <summary>
        /// 查看详情/反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<WarehousingDto> GetAsyncc(int id)
        {
            var Procur = _warehousingAppService.GetAsync(id);
            return Procur;
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult PostWarehousingIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Procurement"></param>
        /// <returns></returns>
        public IActionResult Add(WarehousingDto warehousing)
        {
            var i = _warehousingAppService.CreateAsync(warehousing).Result;
            return Ok(i);
        }
        /// <summary>
        /// 下拉框
        /// </summary>
        /// <returns></returns>
        public IActionResult GetMaterial()
        {
            var list = _warehousingAppService.GetMaterialAsync().Result;
            return Ok(list);
        }
        /// <summary>
        /// 主页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult EntrepotIndex()

        {
            return View();
        }
        // GET: ApproveController/Details/5
        public JsonResult ShowWarehousing(GetWarehousingListDto getWarehousingListDto)
        {
            var Procurements = _warehousingAppService.GetListAsync(getWarehousingListDto).Result;
            return Json(new { data = Procurements.Items, count = Procurements.TotalCount, code = "0", msg = "" });
        }
    }
}
